$(function(){
	var floorTop = [];
	
	$('.floor').each(function(i,ele){
		floorTop.push(ele.offsetTop);
	})
	
	$(document).on('scroll',roll);
	function roll(){
		//$(document).scrollTop()//获得滚动条滚过的距离
		var index = getIndex($(document).scrollTop());
		focus(index);
	}
	function getIndex(rollTop){
		var length =  floorTop.length;
		for(var i=0;i<length;i++){
			if(rollTop>floorTop[i]-200&&rollTop<floorTop[i+1]-200){
				return i;
			}
			if(rollTop>floorTop[length-1]-200){
				return length-1;
			}
		}
	}
	
	function focus(index){
		$('.sideBar li').eq(index).addClass('active').siblings().removeClass('active');
		
	}
	console.log(floorTop);
	$('.sideBar li').click(function(){
		$(document).off('scroll');
		var index = $(this).index();
		var targetTop = floorTop[index];
//		indexOf();
		console.log(navigator.userAgent);//Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0
		if(navigator.userAgent.indexOf('Firefox')>=0){
			$(document.documentElement).animate({scrollTop:targetTop},300,function(){
				$(document).on('scroll',roll);
			});
		}else{
			$(document.body).animate({scrollTop:targetTop},300,function(){
				$(document).on('scroll',roll);
			});
		}
		focus(index);
	})
})











